import { Actions, Store, Mutations } from "../enums/Store";
export const state = () => ({
    [Store.Skin]: {},
	[Store.IsModal]:{},
    [Store.User]: process.browser ? localStorage.getItem('user') || {} : {},
    [Store.Recommend]: {},
    [Store.Latest]: {},
    [Store.LatestDetail]: {}
});
export const mutations = {
    [Mutations.SetSkin](state, data) {
        state[Store.Skin] = data;
    },
    [Mutations.SetUser](state, data) {
        localStorage.setItem('user', data);
        state[Store.User] = data;
    },
    [Mutations.SetRecommend](state, data) {
        state[Store.Recommend] = data;
    },
    [Mutations.SetLatest](state, data) {
        state[Store.Latest] = data;
    },
    [Mutations.SetLatestDetail](state, data) {
        state[Store.LatestDetail] = data;
    },
	[Mutations.SetIsModal](state,data){
	  state[ Store.IsModal ] = data
	},
};
export const actions = {
    async nuxtServerInit({ commit }, { app }) {
        commit(Mutations.SetSkin, 0);
    },
    async [Actions.GetSkin]({ commit }, params) {
        commit(Mutations.SetSkin, params);
    },
    async [Actions.GetUser]({ commit }, user) {
        commit(Mutations.SetUser, user);
    },
	async [Actions.GetIsModal]({commit},params) {
	      commit(Mutations.SetIsModal,params)
	 },
    async [Actions.GetRecommend]({ commit }) {
        commit(Mutations.SetRecommend, await this.$axios.$get('/kugou/recommend?json=true'));
    },
    async [Actions.GetLatest]({ commit }) {
        commit(Mutations.SetLatest, await this.$axios.$get('/kugou/latest?json=true'));
    },
    async [Actions.GetLatestDetail]({ commit }, rankid) {
        commit(Mutations.SetLatestDetail, await this.$axios.$get(`/kugou/detail?json=true&rankid=${rankid}`));
    }
};
